import React, { useState } from 'react'
import './App.css'
import Main from './components/Main'
import Search from './components/Search'
import request from './http/request'
export default function App() {
    let [first, setFirst] = useState(true);
    let [loading, setLoading] = useState(false);
    let [users, setUsers] = useState([]);
    const getKeyword = async (keyword)=>{
        // 设置不是第一次
        setFirst(false);
        // 开启loading
        setLoading(true);
        let res = await request.get('/search/users',{
            params:{
                q:keyword
            }
        })
        console.log('res: ', res);
        setLoading(false);
        // 设置用户状态数据
        setUsers(res.items);
    }
    return (
        <div className="container">
            <Search getKeyword={getKeyword}/>
            <Main first={first} loading={loading} users={users}/>
        </div>
    )
}
